<style type="text/css">.form_pwd_info{display: none;}</style>
<div class="row"> <h3 class="page-header">用户列表</h3></div>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <label><a class="btn btn-primary addText" data-id='{$list.id}'>添加员工</a></label>
            <form action='{:U("Admins/index")}' class="form-inline text-right m-b-5 fr">
                员工名称：<input type="text" name='name' value='{$Think.get.name}' class="form-control mr20 w150">
                手机号码：<input type="text" name='tel' value='{$Think.get.tel}' class="form-control mr20 w150">
                所属组：<select name='gid' class="form-control mr20 w150">
                    <option value='-1'>全部</option>
                    <volist name="groupList" id="group">
                        <option value='{$group.id}' <eq name='Think.get.gid' value="$group.id">selected</eq>>{$group.name}</option>
                    </volist>
                </select>
                状态：<select name='status' class="form-control mr20 w150">
                    <option value='-1'>全部</option>
                    <option value='1' <eq name='Think.get.status' value='1'>selected</eq> >启用</option>
                    <option value='0' <eq name='Think.get.status' value='0'>selected</eq> >禁用</option>
                </select>
                <button class="btn btn-primary" type="submit">搜索</button>
            </form>

            <div class="table-responsive">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th width="60">序号</th>
                             <th>单位名称</th>
                            <th>登录名</th>
                            <th>新闻数</th>
                            <th>所属组</th>
                            <th>最后登录时间</th>
                            <th>手机号码</th>
                            <th width="75">状态</th>
                            <th width="120">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                     <empty name="list">
                            <tr><td colspan="9" align="center">暂无信息</td></tr>
                        </empty>
                        <volist name="list" id="list">
                            <tr>
                                <td>{$i}</td>
                                <td>{$list.remark}</td>
                                <td>{$list.name}</td>
                                <td>{$list.num|default=0}</td>
                                <td>{$list.groupname}</td>
                                <td>
                                   <gt name="list.last_login_time" value='0'>{$list.last_login_time|date='Y-m-d H:i', ###}<else />未登录</gt>
                                </td>   
                                 <td>{$list.tel}</td>                 
                                <eq name="list.id" value="1">
                                   <td class="center"></td>
                                   <td></td>
                                </eq>

                                <eq name="list.id" value="2">
                                    <td class="center">
                                    <button class='btn <eq name="list.status" value="1">btn-primary<else />btn-default</eq> btn-sm setStatus' type="button" data-url='{:U("Admins/setStatus?id=".$list["id"])}' data-status="{$list.status}">
                                    <eq name="list.status" value='1'>启用<else />禁用</eq>
                                    </button>
                                    </td>
                                    <td>
                                    <a class=" btn-sm btn btn-default editText" data-id='{$list.id}'>修改</a>
                                    </td>
                                </eq>

                                <gt name="list.id" value="2">
                                    <td class="center">
                                    <button class='btn <eq name="list.status" value="1">btn-primary<else />btn-default</eq> btn-sm setStatus' type="button" data-url='{:U("Admins/setStatus?id=".$list["id"])}' data-status="{$list.status}"><eq name="list.status" value='1'>启用<else />禁用</eq></button>
                                    </td>
                                    <td>

                                    <a class=" btn-sm btn btn-default editText" data-id='{$list.id}'>修改</a>
                                    <button data-url='{:U("Admins/del?id=".$list["id"])}' class=" btn-sm btn btn-default delBtn" type="button">删除</button>
                                    </td>
                                </gt>
                     
                               
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </div>
            {$page}
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:U('Admins/add')}" id="myform" class="form-horizontal">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h4 class="modal-title">分类管理</h4>
                </div>
                <div class="modal-body">
                <div class="form-group">
                   <label class="col-sm-3 control-label">单位名称：</label>
                   <div class="col-sm-4 input-group">
                        <input class="form-control required" name="remark"  maxlength='11'>
                   </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">登录账号：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="name" maxlength='20'>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">登录密码：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                      <input type="password" id="pwd" class="form-control required" name="pwd" maxlength='15' minlength='6'>
                      <small class="form_pwd_info">若不修改密码，此处请留空</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">确认密码：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                    <input type="password" class="form-control required" equalTo="#pwd" name="pwd2" maxlength='15' minlength='6'>
                        <small class="form_pwd_info">若不修改密码，此处请留空</small>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-3 control-label">选择所属组：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <select class="form-control" id="gid" name="gid">
                            <volist name='groupList' id='group'>
                                <option value="{$group.id}">{$group.name}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-sm-3 control-label">联系方式：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                   <input class="form-control required" name="tel" value="" maxlength='11'>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-4 input-group">
                    <label class="radio-inline">
                        <input type="radio" value="1" id="status1" name="status">启用
                    </label>
                    <label class="radio-inline">
                        <input type="radio" value="0"  id="status2" name="status">禁用
                    </label>
                    </div>
                </div>
               
                </div>
              <input type='hidden' name='id' id="id">
               <div class="modal-footer">
                    <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                    <button class="btn btn-primary" type="submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(function(){
    $('.addText').click(function(){
        $('#myform')[0].reset();
        $(".form_pwd_info").hide();
        $('#myModal').modal('show');
    });
    $('.editText').click(function(){
        $('#myform')[0].reset();
        var id = $(this).data('id'); waiting();
        $.get('{:U("Admins/edit")}', {id: id}, function(data){
            complete();
        if(data.status == 1){
            $(".form_pwd_info").show();
             $("input[type='password']").removeClass('required');
            var _get_info = data.info;
            $('#myform input[name="id"]').val(_get_info.id);
            $('#myform input[name="name"]').val(_get_info.name);
            $('#myform input[name="tel"]').val(_get_info.tel);
            $('#myform select[name="gid"]').val(_get_info.gid);
            $('#myform input[name="remark"]').val(_get_info.remark);
            $("#myform :radio[name=status][value='"+_get_info.status+"']").attr("checked",true);
            $('#myform').attr('action', '{:U("Admins/edit")}');
            $('#myModal').modal('show');
        }else{
             showInfo(data.info);
        //setTimeout('_form_defult_callback()', 1600);
        }
     });
       
    });
      //1.给input框添加blur事件
        $("#pwd").blur(function(){       
        /*
         *  密码长度不小于6位，需包含数字和密码，不包含特殊字符
         */
            var re=/^(?=.*[a-z])(?=.*\d)[^]{6,12}$/;
            var len = re.test($(this).val());
            if(!len) { //匹配不成功, return false
               alert("密码必须含数字、字母且不少于6位");
                return false;
            }
        })
})

</script>